"""In order not having to face the usual problems when importing dumps between
   different databases, the data was turned to a csv and injected programatically
   through this Python script."""
import sqlite3
import pandas as pd
from sqlite3 import Error


def uploadcsv():
    """We import the csv file, create variables for its columns, create a list
       with entries from all columns with the same index and send it to the db
       through sqlite3 request."""
    with open('bkmks6.csv', 'r') as f:
        df = pd.read_csv('bkmks6.csv', sep='|')
        # See bookmarks on "panda_selection"
        tit = df['title']
        com = df['comment']
        lnk = df['link']
        kwd1 = df['k1']
        kwd2 = df['k2']
        kwd3 = df['k3']
        tim = df['tempo']

    try:
        conn = sqlite3.connect('db.sqlite3')
        cur = conn.cursor()
        index = range(156)
        for i in index:
            answers = [tit[i], com[i], lnk[i], kwd1[i], kwd2[i], kwd3[i], tim[i]]
            print(f'title is {tit[i]}')
            print(f'comment is {com[i]}')
            print(f'link is {lnk[i]}')
            print(f'k1 is {kwd1[i]}')
            print(f'k2 is {kwd2[i]}')
            print(f'k3 is {kwd3[i]}')
            print(f'tempo is {tim[i]}')
            query = "INSERT INTO bkmk_bookmarks (title, comment, link, k1, k2, k3, tempo) VALUES (?, ?, ?, ?, ?, ?, ?)"
            print(answers)
            cur.execute(query, answers)
            conn.commit()
    except sqlite3.Error as error:
        print("Error while connecting to db", error)
    finally:
        conn.close()


if __name__ == '__main__':
    uploadcsv()
